home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / undo / StateEdit.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  2.0 KB  |  69 lines

  1. package javax.swing.undo;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Hashtable;
  5. import java.util.Vector;
  6.  
  7. public class StateEdit extends AbstractUndoableEdit {
  8.    protected static final String RCSID = "$Id: StateEdit.java,v 1.6 1997/10/01 20:05:51 sandipc Exp $";
  9.    protected StateEditable object;
  10.    protected Hashtable preState;
  11.    protected Hashtable postState;
  12.    protected String undoRedoName;
  13.  
  14.    public StateEdit(StateEditable var1) {
  15.       this.init(var1, (String)null);
  16.    }
  17.  
  18.    public StateEdit(StateEditable var1, String var2) {
  19.       this.init(var1, var2);
  20.    }
  21.  
  22.    public void end() {
  23.       this.postState = new Hashtable(11);
  24.       this.object.storeState(this.postState);
  25.       this.removeRedundantState();
  26.    }
  27.  
  28.    public String getPresentationName() {
  29.       return this.undoRedoName;
  30.    }
  31.  
  32.    protected void init(StateEditable var1, String var2) {
  33.       this.object = var1;
  34.       this.preState = new Hashtable(11);
  35.       this.object.storeState(this.preState);
  36.       this.postState = null;
  37.       this.undoRedoName = var2;
  38.    }
  39.  
  40.    public void redo() {
  41.       super.redo();
  42.       this.object.restoreState(this.postState);
  43.    }
  44.  
  45.    protected void removeRedundantState() {
  46.       Vector var1 = new Vector();
  47.       Enumeration var2 = this.preState.keys();
  48.  
  49.       while(var2.hasMoreElements()) {
  50.          Object var3 = var2.nextElement();
  51.          if (this.postState.containsKey(var3) && this.postState.get(var3).equals(this.preState.get(var3))) {
  52.             var1.addElement(var3);
  53.          }
  54.       }
  55.  
  56.       for(int var5 = var1.size() - 1; var5 >= 0; --var5) {
  57.          Object var4 = var1.elementAt(var5);
  58.          this.preState.remove(var4);
  59.          this.postState.remove(var4);
  60.       }
  61.  
  62.    }
  63.  
  64.    public void undo() {
  65.       super.undo();
  66.       this.object.restoreState(this.preState);
  67.    }
  68. }
  69.